#include <iostream>
#include <algorithm>
using namespace std;
using ll=long long;
const int N=1e7+10;

ll a[N],b[N],c[N];
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int l,r,s,e;
		scanf("%d%d%d%d",&l,&r,&s,&e);
		int d=(e-s)/(r-l);
		a[l]=a[l]+s;
		a[l+1]-=s;
		a[l+1]+=d;
		// 2 2 2 2 -8-2
		a[r+1]=a[r+1]-d-e;
		a[r+2]+=e;	
	}
	ll maxn=0;
	ll yh=0;
	for(int i=1;i<=n;i++)
	{
		b[i]=b[i-1]+a[i];
		c[i]=c[i-1]+b[i];
		maxn=max(maxn,c[i]);
		yh^=c[i];
	}
	cout<<yh<<' '<<maxn<<endl;
	return 0;
}
